/*
Copyright [2023] [fuwen_soft]
*/
package vip.xiaonuo.sys.modular.sysappinfo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import vip.xiaonuo.core.consts.CommonConstant;
import vip.xiaonuo.core.enums.CommonStatusEnum;
import vip.xiaonuo.core.exception.ServiceException;
import vip.xiaonuo.core.factory.PageFactory;
import vip.xiaonuo.core.pojo.page.PageResult;
import vip.xiaonuo.core.util.PoiUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vip.xiaonuo.sys.modular.sysappinfo.entity.SysAppInfo;
import vip.xiaonuo.sys.modular.sysappinfo.enums.SysAppInfoExceptionEnum;
import vip.xiaonuo.sys.modular.sysappinfo.mapper.SysAppInfoMapper;
import vip.xiaonuo.sys.modular.sysappinfo.param.SysAppInfoParam;
import vip.xiaonuo.sys.modular.sysappinfo.service.SysAppInfoService;

import javax.annotation.Resource;
import java.util.List;

/**
 * APP介绍详情service接口实现类
 *
 * @author yanwei
 * @date 2023-03-21 12:07:25
 */
@Service
public class SysAppInfoServiceImpl extends ServiceImpl<SysAppInfoMapper, SysAppInfo> implements SysAppInfoService {

    @Override
    public PageResult<SysAppInfo> page(SysAppInfoParam sysAppInfoParam) {
        QueryWrapper<SysAppInfo> queryWrapper = new QueryWrapper<>();
        if (ObjectUtil.isNotNull(sysAppInfoParam)) {

            // 根据网站标题 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getAppTitle())) {
                queryWrapper.lambda().eq(SysAppInfo::getAppTitle, sysAppInfoParam.getAppTitle());
            }
            // 根据app名称 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getAppName())) {
                queryWrapper.lambda().eq(SysAppInfo::getAppName, sysAppInfoParam.getAppName());
            }
            // 根据网站ICON 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getIconUrl())) {
                queryWrapper.lambda().eq(SysAppInfo::getIconUrl, sysAppInfoParam.getIconUrl());
            }
            // 根据IOS版本介绍 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getIosInfo())) {
                queryWrapper.lambda().eq(SysAppInfo::getIosInfo, sysAppInfoParam.getIosInfo());
            }
            // 根据IOS下载链接 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getIosUrl())) {
                queryWrapper.lambda().eq(SysAppInfo::getIosUrl, sysAppInfoParam.getIosUrl());
            }
            // 根据安卓介绍 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getAndriodInfo())) {
                queryWrapper.lambda().eq(SysAppInfo::getAndriodInfo, sysAppInfoParam.getAndriodInfo());
            }
            // 根据安卓下载地址 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getAndriodUrl())) {
                queryWrapper.lambda().eq(SysAppInfo::getAndriodUrl, sysAppInfoParam.getAndriodUrl());
            }
            // 根据服务标题 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getServiceHead())) {
                queryWrapper.lambda().eq(SysAppInfo::getServiceHead, sysAppInfoParam.getServiceHead());
            }
            // 根据服务内容 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getServiceContent())) {
                queryWrapper.lambda().eq(SysAppInfo::getServiceContent, sysAppInfoParam.getServiceContent());
            }
            // 根据APP介绍标题 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getAppInfoHead())) {
                queryWrapper.lambda().eq(SysAppInfo::getAppInfoHead, sysAppInfoParam.getAppInfoHead());
            }
            // 根据APP介绍详情 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getAppInfoContent())) {
                queryWrapper.lambda().eq(SysAppInfo::getAppInfoContent, sysAppInfoParam.getAppInfoContent());
            }
            // 根据APP评价标题 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getEvaluationHead())) {
                queryWrapper.lambda().eq(SysAppInfo::getEvaluationHead, sysAppInfoParam.getEvaluationHead());
            }
            // 根据APP评价内容 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getEvaluationContent())) {
                queryWrapper.lambda().eq(SysAppInfo::getEvaluationContent, sysAppInfoParam.getEvaluationContent());
            }
            // 根据APP特色标题 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getFeaturesHead())) {
                queryWrapper.lambda().eq(SysAppInfo::getFeaturesHead, sysAppInfoParam.getFeaturesHead());
            }
            // 根据APP特色内容 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getFeaturesContent())) {
                queryWrapper.lambda().eq(SysAppInfo::getFeaturesContent, sysAppInfoParam.getFeaturesContent());
            }
            // 根据关于我们标题 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getTextHead())) {
                queryWrapper.lambda().eq(SysAppInfo::getTextHead, sysAppInfoParam.getTextHead());
            }
            // 根据关于我们内容 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getTextContent())) {
                queryWrapper.lambda().eq(SysAppInfo::getTextContent, sysAppInfoParam.getTextContent());
            }
            // 根据关于我们链接 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getTextUrl())) {
                queryWrapper.lambda().eq(SysAppInfo::getTextUrl, sysAppInfoParam.getTextUrl());
            }
            // 根据网站版权信息 查询
            if (ObjectUtil.isNotEmpty(sysAppInfoParam.getCopyright())) {
                queryWrapper.lambda().eq(SysAppInfo::getCopyright, sysAppInfoParam.getCopyright());
            }
        }
        return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper));
    }

    @Override
    public List<SysAppInfo> list(SysAppInfoParam sysAppInfoParam) {
        return this.list();
    }

    @Override
    public void add(SysAppInfoParam sysAppInfoParam) {
        SysAppInfo sysAppInfo = new SysAppInfo();
        BeanUtil.copyProperties(sysAppInfoParam, sysAppInfo);
        this.save(sysAppInfo);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(List<SysAppInfoParam> sysAppInfoParamList) {
        sysAppInfoParamList.forEach(sysAppInfoParam -> {
            this.removeById(sysAppInfoParam.getId());
        });
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void edit(SysAppInfoParam sysAppInfoParam) {
        SysAppInfo sysAppInfo = this.querySysAppInfo(sysAppInfoParam);
        BeanUtil.copyProperties(sysAppInfoParam, sysAppInfo);
        this.updateById(sysAppInfo);
    }

    @Override
    public SysAppInfo detail(SysAppInfoParam sysAppInfoParam) {
        return this.querySysAppInfo(sysAppInfoParam);
    }

    /**
     * 获取APP介绍详情
     *
     * @author yanwei
     * @date 2023-03-21 12:07:25
     */
    private SysAppInfo querySysAppInfo(SysAppInfoParam sysAppInfoParam) {
        SysAppInfo sysAppInfo = this.getById(sysAppInfoParam.getId());
        if (ObjectUtil.isNull(sysAppInfo)) {
            throw new ServiceException(SysAppInfoExceptionEnum.NOT_EXIST);
        }
        return sysAppInfo;
    }

    @Override
    public void export(SysAppInfoParam sysAppInfoParam) {
        List<SysAppInfo> list = this.list(sysAppInfoParam);
        PoiUtil.exportExcelWithStream("SnowySysAppInfo.xls", SysAppInfo.class, list);
    }

}
